<?php
declare (strict_types = 1);

namespace app\service\logic\common\maintain;

use app\model\communal\InfoMaintainModel;
use app\service\logic\BaseService;
use think\Model;

final class InfoService extends BaseService
{
    protected string $modelClassName = 'InfoMaintainModel';
    
    /**
     * 查找单挑记录
     *
     * @param $params
     * @return array|Model
     */
    public function getSimpleDetail($params)
    {
        return InfoMaintainModel::where('type', $params['type'])->findOrEmpty();
    }

    /**
     * 创建 or 修改
     *
     * @param $params
     * @return InfoMaintainModel|Model
     */
    public function create($params)
    {
        $model = $this->getSimpleDetail($params);
        if ($model->isExists()) {
            $model->save($params);
        } else {
            $model = InfoMaintainModel::create($params);
        }
        return $model;
    }
}
